<#assign path="${springMacroRequestContext.getContextPath()}">
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>课程信息管理系统</title>
    <meta name="keywords" />
    <meta name="description" />
    <meta name="author" content="DeathGhost" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <link rel="icon" href="${path}/static/images/icon/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="${path}/static/css/style.css" />
    <script src="${path}/static/javascript/jquery.js"></script>
    <script src="${path}/static/javascript/plug-ins/customScrollbar.min.js"></script>
    <script src="${path}/static/javascript/plug-ins/echarts.min.js"></script>
    <script src="${path}/static/javascript/plug-ins/layerUi/layer.js"></script>
    <script src="${path}/static/editor/ueditor.config.js"></script>
    <script src="${path}/static/editor/ueditor.all.js"></script>
    <script src="${path}/static/javascript/plug-ins/pagination.js"></script>
    <script src="${path}/static/javascript/public.js"></script>
    <script src="${path}/static/javascript/menu.js"></script>
</head>
<style type="text/css">
    .kd {
        display: block
    }

    .inputcs {
        width: 300px
    }

    .btncs {

    }
</style>
<body>
<div class="main-wrap">
    <input type="hidden" id="power222" name="power" value="${Session["power"]}" >
    <#include "/leftmenu.ftl"/>
    <div class="content-wrap">
        <header class="top-hd">
            <div class="hd-lt">
                <a class="icon-reorder"></a>
            </div>
            <div class="hd-rt">
                <ul>
                    <li>
                        <a><i class="icon-user"></i>系统时间:<em>${Session["time"]}</em></a>
                    </li>
                    <li>
                        <a><i class="icon-user"></i>${Session["roleName"]}:<em>${Session["user"].name}</em></a>
                    </li>
                    <li>
                        <a onclick="quit();" ><i class="icon-signout"></i>安全退出</a>
                    </li>
                </ul>
            </div>
        </header>
        <main class="main-cont content mCustomScrollbar"> <!--开始::内容-->
            <div class="page-wrap">
                <section class="page-hd">
                    <header>
                        <h2 class="title">角色管理</h2>
                    </header>
                    <hr>
                </section>
                <form action="${path}/Role/queryAll" method="post">
                    <div class="form-group-col-2 " style="display: inline-block;">
                        <div class="form-label">角色名称：</div>
                        <div class="form-cont">
                            <input type="text" id="name11" name="rolename"
                                   value="" class="form-control form-boxed inputcs"
                                   style="width: 200px">
                        </div>
                    </div>
                    <div class="form-group-col-2 " style="display: inline-block;">
                        <div class="form-cont">
                            <button class="btn btn-primary radius">搜索</button>
                        </div>
                    </div>
                </form>
                <table class="table table-bordered table-striped table-hover">
                    <thead>
                    <tr>
                        <th>角色ID</th>
                        <th>角色名称</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <#if list?exists>
                        <#list list as role>
                            <tr class="cen">
                            <td>${role["roleid"]}</td>
                            <td> ${role["rolename"]}</td>
                            <td><a title="编辑" class="mr-5" onclick="show('${role["roleid"]}')">编辑</a>
                        <a title="详情" class="mr-5" onclick="show1('${role["roleid"]}')">详情</a>
                            </tr>
                        </#list>
                    </#if>
                    </tbody>
                </table>
            </div>
        </main>
        <footer class="btm-ft">
            <p class="clear">
                <span class="fl">©Copyright 2016</span> <span class="fr text-info">
						<em class="uppercase"> <i class="icon-user"></i> management
							system
					</em>
					</span>
            </p>
        </footer>
    </div>
</div>
<div class="mask"></div>
<div class="dialog" style="width: 650px">
    <div class="dialog-hd">
        <strong class="lt-title">角色管理</strong> <a
                class="rt-operate icon-remove JclosePanel" title="关闭"></a>
    </div>
    <form action="" method="post">
        <div class="dialog-bd">
            <div class="form-group-col-2">
                <div class="form-label ">角色ID：</div>
                <div class="form-cont">
                    <input type="text" id="roleid1" readonly="readonly"
                           class="form-control form-boxed inputcs">
                </div>
            </div>
            <div class="form-group-col-2 ">
                <div class="form-label">角色名称：</div>
                <div class="form-cont">
                    <input type="text" id="rolename1"  readonly="readonly"
                           class="form-control form-boxed inputcs">
                    <input type="hidden" id="flag">
                </div>
            </div>
            <div class="form-group-col-2">
                <div class="form-label">权限：</div>
                <div class="form-cont">
                    <label class="check-box kd">
                        <input type="checkbox" id="11011" value="1101" class="power" />
                        <span>教师信息管理</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="11021"  value="1102" class="power"/>
                        <span>学生信息管理</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="11031"  value="1103" class="power"/>
                        <span>课程信息管理</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="12011"  value="1201" class="power"/>
                        <span>发布公告</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="12021"  value="1202" class="power"/>
                        <span>公告修改</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="12031"  value="1203" class="power"/>
                        <span>公告删除</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="13011"  value="1301" class="power"/>
                        <span>教师排课</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="13021"  value="1302" class="power"/>
                        <span>学生选课</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="13031"  value="1303" class="power"/>
                        <span>课表查看</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="13041"  value="1304" class="power"/>
                        <span>学生反馈</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="14011" value="1401" class="power"/>
                        <span>上传成绩</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="14021"  value="1402" class="power"/>
                        <span>成绩查询</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="15011"  value="1501" class="power"/>
                        <span>角色管理</span>
                    </label>
                    <label class="check-box kd">
                        <input type="checkbox" id="15021"  value="1502" class="power"/>
                        <span>修改密码</span>
                    </label>
                </div>
            </div>

        </div>
    </form>
    <div class="dialog-ft" style="text-align: center; padding: -20px">
        <button type="submit" class="btn btn-info JyesBtn" id="submit11"
                onclick="subdata()">提交</button>
        <button class="btn btn-secondary JnoBtn">关闭</button>
    </div>
</div>

<div class="panel panel-default">
    <div class="panel-bd">
        <button id="btnModify" class="btn btn-info JopenMaskPanel mr-10"></button>
    </div>
</div>
<script type="text/javascript">
    function subdata() {
        var   ids= new Array();
        $("input[class='power']:checked").each(function(i,k){
            var itemId=$(this).val();
            ids[i]=itemId;
        });

        var roleid1 = $("#roleid1").val();
        var rolename1 = $("#rolename1").val();
        var powercontent = ids.toString();
        //更新
        $.ajax({
            type : 'POST',
            url : "${path}/Role/update",
            dataType : 'json',
            cache : false,
            async : false,
            data : {
                id : roleid1,
                rolename : rolename1,
                powerContent : powercontent
            },
            success : function(data) {
                window.location.reload();
            },
            error : function() {
                window.location.reload();
            }
        });

    }

    //编辑展示
    function show(id) {
        $("#btnModify").click();
        $('#roleid1').attr("disabled", false);
        $('#rolename1').attr("disabled", false);
        cancelCheck();
        $(".power").attr("disabled", false);
        $('#submit11').css("display", "inline-block");
        $.ajax({
            type : 'POST',
            url : "${path}/Role/queryOne",
            dataType : 'json',
            cache : false,
            async : false,
            data : {
                ID : id
            },
            success : function(data) {
                $("#roleid1").val(data.roleid);
                $("#rolename1").val(data.rolename);
                $("#flag").val("1");
                checkdeck(data.powerid);
            },
            error : function() {

                window.location.reload();
            }
        });

    }

    //添加
    function show2() {
        $('#submit11').css("display", "inline-block");
        $("#btnModify").click();
        $('#roleid1').attr("disabled", false);
        $('#rolename1').attr("disabled", false);

        $("#rolename1").val("");
        $("#roleid1").val("");
        $("#flag").val("3");
    }
    //查看展示
    function show1(id) {
        cancelCheck();
        $("#btnModify").click();
        var powerID1;
        $.ajax({
            type : 'POST',
            url : "${path}/Role/queryOne",
            dataType : 'json',
            cache : false,
            async : false,
            data : {
                ID : id
            },
            success : function(data) {
                $("#roleid1").val(data.roleid);
                $("#rolename1").val(data.rolename);
                $("#flag").val("2");
                powerID1 = data.powerid;


            },
            error : function() {

                window.location.reload();
            }
        });
        checkdeck(powerID1);
        $(".power").attr("disabled", true);
        $('#rolename1').attr("disabled", true);
        $('#roleid1').attr("disabled", true);
        $('#submit11').css("display", "none");
    }



    function quit(){
        if(confirm("你确定要退出登陆吗？")){
            window.location.href = "${path}/User/quit";
        }
    }
    function cancelCheck(){
        $("#11011").attr("checked",false);
        $("#11021").attr("checked",false);
        $("#11031").attr("checked",false);
        $("#12011").attr("checked",false);
        $("#12021").attr("checked",false);
        $("#12031").attr("checked",false);
        $("#13011").attr("checked",false);
        $("#13021").attr("checked",false);
        $("#13031").attr("checked",false);
        $("#13041").attr("checked",false);
        $("#14011").attr("checked",false);
        $("#14021").attr("checked",false);
        $("#15011").attr("checked",false);
        $("#15021").attr("checked",false);
    }

    function checkdeck(powerid){
        if(powerid.indexOf("1101")>=0){
            $("#11011").attr("checked",true);
        }
        if(powerid.indexOf("1102")>=0){
            $("#11021").attr("checked",true);
        }
        if(powerid.indexOf("1103")>=0){
            $("#11031").attr("checked",true);
        }
        if(powerid.indexOf("1201")>=0){
            $("#12011").attr("checked",true);
        }
        if(powerid.indexOf("1202")>=0){
            $("#12021").attr("checked",true);
        }
        if(powerid.indexOf("1203")>=0){
            $("#12031").attr("checked",true);
        }
        if(powerid.indexOf("1301")>=0){
            $("#13011").attr("checked",true);
        }
        if(powerid.indexOf("1302")>=0){
            $("#13021").attr("checked",true);
        }
        if(powerid.indexOf("1303")>=0){
            $("#13031").attr("checked",true);
        }
        if(powerid.indexOf("1304")>=0){
            $("#13041").attr("checked",true);
        }
        if(powerid.indexOf("1401")>=0){
            $("#14011").attr("checked",true);
        }
        if(powerid.indexOf("1402")>=0){
            $("#14021").attr("checked",true);
        }
        if(powerid.indexOf("1501")>=0){
            $("#15011").attr("checked",true);
        }
        if(powerid.indexOf("1502")>=0){
            $("#15021").attr("checked",true);
        }
    }
    //添加展示
</script>
</body>
</html>
